import request from '../../utils/request'
import { praseStrEmpty } from '@/utils/z.js'

/**
 * 查询用户列表
 *
 * @param {any} query
 * @returns 用户列表
 */
export const listUser =  (query: any) => {
    return  request({
        url: "/system/user/list",
        method: "get",
        params: query,
    });
};

/**
 * 通过用户ID查询用户详细
 *
 * @param {string} userId 用户ID
 * @returns 用户信息
 */
export const getUser =  (userId: any) => {
    return  request({
        url: "/system/user/" + praseStrEmpty(userId),
        method: "get",
    });
};

/**
 * 新增用户
 *
 * @param {any} data
 * @returns
 */
export const addUser =  (data: any) => {
    return  request({
        url: "/system/user",
        method: "post",
        data: data,
    });
};

/**
 * 修改用户
 *
 * @param {any} data
 * @returns
 */
export const updateUser =  (data: any) => {
    return  request({
        url: "/system/user",
        method: "put",
        data: data,
    });
};

/**
 * 删除用户
 *
 * @param {string} userId 用户ID
 * @returns
 */
export const delUser =  (userId: string) => {
    return  request({
        url: "/system/user/" + userId,
        method: "delete",
    });
};

/**
 * 导出用户
 *
 * @param {object} query
 * @returns
 */
export const exportUser =  (query: any) => {
    return  request({
        url: "/system/user/export",
        method: "get",
        params: query,
    });
};

/**
 * 用户密码重置
 *
 * @param {string} userId   用户ID
 * @param {string} password 密码
 * @returns
 */
export const resetUserPwd =  (userId: any, password: any) => {
    return  request({
        url: "/system/user/resetPwd",
        method: "put",
        data: {
            userId,
            password,
        },
    });
};

/**
 * 用户状态修改
 *
 * @param {string} userId 用户ID
 * @param {string} status 用户状态
 * @returns
 */
export const changeUserStatus =  (userId: string, status: string) => {
    return  request({
        url: "/system/user/changeStatus",
        method: "put",
        data: {
            userId,
            status,
        },
    });
};

/**
 * 查询用户个人信息
 *
 * @returns
 */
export const getUserProfile =  () => {
    return  request({
        url: "/system/user/profile",
        method: "get",
    });
};

/**
 * 修改用户个人信息
 *
 * @param {object} data
 * @returns
 */
export const updateUserProfile =  (data: any) => {
    return  request({
        url: "/system/user/profile",
        method: "put",
        data: data,
    });
};

/**
 * 用户密码重置
 *
 * @param {string} oldPassword 旧密码
 * @param {string} newPassword 新密码
 * @returns
 */
export const updateUserPwd =  (oldPassword: any, newPassword: any) => {
    return  request({
        url: "/system/user/profile/updatePwd",
        method: "put",
        params: {
            oldPassword,
            newPassword,
        },
    });
};

/**
 * 用户头像上传
 *
 * @param {Object} data
 * @returns
 */
export const uploadAvatar =  (data: any) => {
    return  request({
        url: "/system/user/profile/avatar",
        method: "post",
        data: data,
    });
};

/**
 * 下载用户导入模板
 *
 * @returns
 */
export const importTemplate =  () => {
    return  request({
        url: "/system/user/importTemplate",
        method: "get",
    });
};

// 查询授权角色
export const getAuthRole =  (userId: any) => {
    return  request({
        url: "/system/user/authRole/" + userId,
        method: "get",
    });
};

// 保存授权角色
export const updateAuthRole =  (data: any) => {
    return  request({
        url: "/system/user/authRole",
        method: "put",
        params: data,
    });
};
